package main

import (
	"log"

	"time"

	"github.com/larspensjo/config"
	"github.com/tarm/serial"
)

func main() {
	c, _ := config.ReadDefault("weight_server.conf")
	port, _ := c.String("default", "port")
	baud, _ := c.Int("default", "baud")
	serial_c := &serial.Config{Name: port, Baud: baud, ReadTimeout: time.Millisecond * 100}
	s, err := serial.OpenPort(serial_c)
	if err != nil {
		log.Fatal(err)
	}

	buf := make([]byte, 128)
	//for {
	//time.Sleep(time.Millisecond * 100)
	_, err := s.Write([]byte("RN\r\n"))
	if err != nil {
		log.Fatal(err)
	}

	_, err = s.Read(buf)
	log.Println("=====================")
	log.Println(buf)
	log.Println(string(buf))
	log.Println("---------------------")
	if err != nil {
		log.Fatal(err)
	}
	log.Println("++++++++++++++++++++++")
	//}

}
